// ****************fixed.h********
// Header file for fixed point routines
// Jonathan W. Valvano 1/27/09

//  This example accompanies the books
//   "Embedded Microcomputer Systems: Real Time Interfacing",
//         Engineering, copyright (c) 2006,
//   "Introduction to Embedded Microcomputer Systems: 
//    Motorola 6811 and 6812 Simulation", Thomson, copyright (c) 2002

// Copyright 2009 by Jonathan W. Valvano, valvano@mail.utexas.edu 
//    You may use, edit, run or distribute this file 
//    as long as the above copyright notice remains 

//**********Sqrt**********
// sqrt for 16-bit integers
// input: 16-bit unsigned number
// output: sqrt(input)
// e.g., sqrt(1600) = 40
// no overflow error possible
unsigned short Sqrt(unsigned short s);

//**********Fixed_Sqrt2**********
// sqrt for decimal fixed-point numbers with 0.01 resolution
// input: integer part of an unsigned fixed-point number
// output: integer part of sqrt(input)
// e.g., sqrt(16.00) = 4.00, 1600 -> 400
// no overflow error possible
unsigned short Fixed_Sqrt2(unsigned short s); 

//**********Fixed_Sqrt3**********
// sqrt for decimal fixed-point numbers with 0.001 resolution
// input: integer part of an unsigned fixed-point number
// output: integer part of sqrt(input)
// e.g., sqrt(16.000) = 4.000, 16000 -> 4000
// no overflow error possible
unsigned short Fixed_Sqrt3(unsigned short s); 

//**********Fixed_uMult2**********
// multiply for decimal fixed-point numbers with 0.01 resolution
// inputs: two integer parts of unsigned fixed-point numbers
// output: integer part of the product of the two inputs
//         result =(n1*n2)/100
// e.g., mult(16.00*2.50) = 40.00, 1600,250 -> 4000
// if overflow 65535 is returned 
unsigned short Fixed_uMult2(unsigned short n1, unsigned short n2);

//**********Fixed_uMult3**********
// multiply for decimal fixed-point numbers with 0.001 resolution
// inputs: two integer parts of unsigned fixed-point numbers
// output: integer part of the product of the two inputs
//         result =(n1*n2)/1000
// e.g., mult(16.000*2.500) = 40.000, 16000,2500 -> 40000
// if overflow 65535 is returned 
unsigned short Fixed_uMult3(unsigned short n1, unsigned short n2);


//**********Fixed_sMult2**********
// multiply for decimal fixed-point numbers with 0.01 resolution
// inputs: two integer parts of signed fixed-point numbers
// output: integer part of the product of the two inputs
//         result =(n1*n2)/100
// e.g., mult(1.60*-2.50) = -4.00, 160,-250 -> -400
// if overflow -32768 is returned 
unsigned short Fixed_sMult2(short n1, short n2);


//**********Fixed_sMult3**********
// multiply for decimal fixed-point numbers with 0.001 resolution
// inputs: two integer parts of signed fixed-point numbers
// output: integer part of the product of the two inputs
//         result =(n1*n2)/1000
// e.g., mult(1.600*-2.500) = -4.000, 1600,-2500 -> -4000
// if overflow -32768 is returned 
unsigned short Fixed_sMult3(short n1, short n2);
